from django.db import models


# Create your models here.
# 分类表
class Category(models.Model):
    # id = models.IntegerField(auto_created=True, primary_key=True)
    name = models.CharField(max_length=20)
    password = models.CharField(max_length=50)
    # null=True允许在数据库中存储NULL值, blank=True并且在表单中允许为空
    # related_name='children' 设置反向关联的名称，可以通过parent.children访问所有子类别
    parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')

    def __str__(self):
        return self.name

# decode,encode

# 职位表
class Position(models.Model):
    name = models.CharField(max_length=100)
    number = models.CharField(max_length=20)
    level = models.IntegerField()
    category = models.ForeignKey(Category, on_delete=models.CASCADE)

    def __str__(self):
        return self.name